﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CNVP.JShop.UI;
using CNVP.Framework.Utils;

namespace CNVP.JShop.Web.Admin.CommonWindows
{
    public partial class AjaxProAddRefAll : AdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string ProductID = Request.QueryString["ProductID"].ToString();
                if (string.IsNullOrEmpty(ProductID) || (!Public.IsNumber(ProductID)))
                {
                    ProductID = "0";
                }
                string ProductTypeID = Request.QueryString["ProductTypeID"].ToString();
                if (string.IsNullOrEmpty(ProductTypeID) || (!Public.IsNumber(ProductTypeID)))
                {
                    ProductTypeID = "0";
                }
                string TypeStr = Request.QueryString["TypeStr"];
                switch (TypeStr)
                {
                    case "RefDescripttion":
                        var model_RefDescripttion = new BLL.CNVP_ProductType().GetSingle_CNVP_ProductTypeById(int.Parse(ProductTypeID));
                        if (model_RefDescripttion != null)
                        {
                            string IsRefDescripttion = model_RefDescripttion.IsRefDescripttion.ToString();
                            if (IsRefDescripttion == "1")
                            {
                                string html = "";
                                html += "<h3>属性参数：</h3>";
                                html += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"division\">";
                                var list_RefDescripttion = new BLL.CNVP_ProTypeRefDescripttion().GetAll_CNVP_ProTypeRefDescripttion(int.Parse(ProductTypeID));
                                if (list_RefDescripttion != null && list_RefDescripttion.Count > 0)
                                {
                                    for (int i = 0; i < list_RefDescripttion.Count; i++)
                                    {
                                        string PDStandardVaule_Str = "";
                                        string PDStandardID_Str = "";
                                        try
                                        {
                                            string PDStandardVaule = "";
                                            int PDStandardID = 0;
                                            var model_ProPropertyDescripttion=new BLL.CNVP_ProPropertyDescripttion().GetStandardVauleByProTypeRefDescripttionIDAndProductID(list_RefDescripttion[i].ID, int.Parse(ProductID));
                                            if (model_ProPropertyDescripttion != null)
                                            {
                                                PDStandardVaule = model_ProPropertyDescripttion.StandardValue;
                                                PDStandardID = model_ProPropertyDescripttion.ID;
                                            }
                                            PDStandardVaule_Str = "value=\"" + PDStandardVaule + "\"";
                                            PDStandardID_Str = "value=\"" + PDStandardID + "\"";
                                        }
                                        catch
                                        {
                                            PDStandardVaule_Str = "";
                                            PDStandardID_Str = "";
                                        }
                                        string ControlType = "<input id=\"CKRefDescripttion\" name=\"CKRefDescripttion\" type=\"checkbox\" checked=\"checked\" " + PDStandardID_Str + " class=\"Display\" />";
                                        ControlType += "  <input id=\"RefDescripttionID\" type=\"hidden\" name=\"RefDescripttionID\" value=\"" + list_RefDescripttion[i].ID + "\" />";
                                        ControlType += "<input id=\"RefDescripttion\" type=\"text\" name=\"RefDescripttion\" " + PDStandardVaule_Str + " />";
                                        html += "<tr>";
                                        html += "<th>" + list_RefDescripttion[i].DescripttionName + "</th>";
                                        html += "<td>" + ControlType + "</td>";
                                        html += "</tr>";
                                    }
                                }
                                html += "</table>";
                                Response.Write(html);
                            }
                        }
                        break;
                    case "RefExtendProperty":
                        var model_RefExtendProperty = new BLL.CNVP_ProductType().GetSingle_CNVP_ProductTypeById(int.Parse(ProductTypeID));
                        if (model_RefExtendProperty != null)
                        {
                            string IsRefExtendProperty = model_RefExtendProperty.IsRefExtendProperty.ToString();
                            if (IsRefExtendProperty == "1")
                            {
                                string html = "";
                                html += "<h3>扩展属性：</h3>";
                                html += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"division\">";
                                var list_RefExtendProperty = new BLL.CNVP_ProTypeRefExtendProperty().GetAll_CNVP_ProTypeRefExtendProperty(int.Parse(ProductTypeID));
                                if (list_RefExtendProperty != null && list_RefExtendProperty.Count > 0)
                                {
                                    for (int i = 0; i < list_RefExtendProperty.Count; i++)
                                    {
                                        string EPStandardVaule_Str = "";
                                        string EPStandardVauleOutValue = "";
                                        string EPStandardID_Str = "";
                                        try
                                        {
                                            string EPStandardVaule = "";
                                            int EPStandardID = 0;
                                            var model_ProExtendeProperty=new BLL.CNVP_ProExtendeProperty().GetEPStandardVauleByProTypeRefExtendPropertyIDAndProductID(list_RefExtendProperty[i].ID, int.Parse(ProductID));
                                            if (model_ProExtendeProperty != null)
                                            {
                                                EPStandardVaule = model_ProExtendeProperty.StandardVaule;
                                                EPStandardID = model_ProExtendeProperty.ID;
                                            }
                                            EPStandardVaule_Str = "value=\"" + EPStandardVaule + "\"";
                                            EPStandardVauleOutValue = EPStandardVaule;
                                            EPStandardID_Str = "value=\"" + EPStandardID + "\"";
                                        }
                                        catch
                                        {
                                            EPStandardVaule_Str = "";
                                            EPStandardID_Str = "";
                                            EPStandardVauleOutValue = "";
                                        }
                                        string ControlType = "";
                                        if (list_RefExtendProperty[i].StageShowType == 3 || list_RefExtendProperty[i].StageShowType == 4)
                                        {
                                            string StageShowType_Html = "";
                                            StageShowType_Html += "<input id=\"CKRefExtendProperty\" name=\"CKRefExtendProperty\" type=\"checkbox\" checked=\"checked\" " + EPStandardID_Str + " class=\"Display\" />";
                                            StageShowType_Html += "<input id=\"RefExtendPropertyID\" type=\"hidden\" name=\"RefExtendPropertyID\" value=\"" + list_RefExtendProperty[i].ID + "\" />";
                                            StageShowType_Html += "<input id=\"RefExtendProperty\" type=\"text\" name=\"RefExtendProperty\" " + EPStandardVaule_Str + " />";
                                            ControlType = StageShowType_Html;
                                        }
                                        else
                                        {
                                            string[] SelectItemValueArray = list_RefExtendProperty[i].SelectItemValue.Split(Convert.ToChar("|"));
                                            string StageShowType_Html = "";
                                            StageShowType_Html += "<input id=\"CKRefExtendProperty\" name=\"CKRefExtendProperty\" type=\"checkbox\" checked=\"checked\" " + EPStandardID_Str + " class=\"Display\" />";
                                            StageShowType_Html += "<input id=\"RefExtendPropertyID\" type=\"hidden\" name=\"RefExtendPropertyID\" value=\"" + list_RefExtendProperty[i].ID + "\" />";
                                            StageShowType_Html += "<select id=\"RefExtendProperty\" name=\"RefExtendProperty\" >";
                                            StageShowType_Html += "	<option value=\"\">--请选择--</option>";
                                            for (int k = 0; k < SelectItemValueArray.Length; k++)
                                            {
                                                string selectCB = "";
                                                if (EPStandardVauleOutValue == SelectItemValueArray[k])
                                                {
                                                    selectCB = "selected='selected'";
                                                }
                                                if (SelectItemValueArray[k].ToString() != "")
                                                {
                                                    StageShowType_Html += "<option value=\"" + SelectItemValueArray[k].ToString() + "\" " + selectCB + ">" + SelectItemValueArray[k].ToString() + "</option>";
                                                }
                                            }
                                            StageShowType_Html += "</select>";
                                            ControlType = StageShowType_Html;
                                        }
                                        html += "<tr>";
                                        html += "<th>" + list_RefExtendProperty[i].ExtendPropertyName + "</th>";
                                        html += "<td>" + ControlType + "</td>";
                                        html += "</tr>";
                                    }
                                }
                                html += "</table>";
                                Response.Write(html);
                            }
                        }
                        break;

                }
            }
            catch
            {
                Response.Write("");
            }
        }
    }
}